package com.jingdianjichi.subject.domain.handler.Subject;

import com.jingdianjichi.subject.common.enums.IsDeleteFlagEnum;
import com.jingdianjichi.subject.common.enums.SubjectTypeEnums;
import com.jingdianjichi.subject.domain.convert.RadioSubjectConverter;
import com.jingdianjichi.subject.domain.convert.SubjectInfoConvert;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBO;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.entity.SubjectRadio;
import com.jingdianjichi.subject.infra.basic.service.SubjectRadioService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * 单选策略类
 */
@Component

public class RadioTypeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectRadioService subjectRadioService;
    @Override
    public void add(SubjectInfoBO subjectInfobo) {
        List<SubjectRadio> subjectRadios=new LinkedList<>();
        subjectInfobo.getOptionList().forEach(option->{
            SubjectRadio subjectRadio= RadioSubjectConverter.INSTANCE.convertBoToInfo(option);
            subjectRadio.setSubjectId(subjectInfobo.getId());
            subjectRadio.setIsDeleted(IsDeleteFlagEnum.UN_DELETED.getCode());
            subjectRadios.add(subjectRadio);
        });
        subjectRadioService.batchInsert(subjectRadios);
    }

    @Override
    public SubjectTypeEnums getSubjectType() {
        return  SubjectTypeEnums.RADIO;
    }

    /**
     * 按类型查询答案（各个答案数据库不同）
     * @param id
     * @return
     */
    @Override
    public SubjectOptionBo query(Long id) {
        SubjectRadio subjectRadio=subjectRadioService.queryById(id);
        SubjectOptionBo subjectOptionBo=new SubjectOptionBo();
//        subjectOptionBo.setSubjectAnswer(subjectRadio.get);
        return subjectOptionBo;
    }
}
